/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controller;

import config.Debug;
import config.Settings;
import data.HttpRequest;

/**
 * 
 * @author Yang Wang <yang@digitalmenubox.com>
 */
public class NewPlayerChecker implements Runnable {

	public static String newline = System.getProperty("line.separator");
	public static double newestVersion = Settings.VERSION;

	// check online if there is an new player available, we should only check
	// for new updates every one or two days
	// if there is new player, download it and shutdown the current player
	// replace the current player with the new player
	// run the new player?

	/**
	 * Checks if there is a newer version of the player.
	 * 
	 */
	// public static boolean hasNewVersion() {
	// newestVersion = HttpRequest.getNewestPlayerVersion();
	// if (newestVersion > Settings.VERSION) {
	// return true;
	// } else {
	// return false;
	// }
	// }

	public static void downloadNewPlayer() {
		// download the new player
		/*
		 * Downloader downloader = Downloader.createDownloader(); String
		 * newPlayerFilename = "dmbplayer" +
		 * Double.toString(newestVersion).replace(".", "");
		 * System.out.println(newPlayerFilename); boolean downloaded =
		 * downloader
		 * .download("http://www.digitalmarketingbox.com/webtool/boxdata/player/"
		 * + newPlayerFilename + ".zip", newPlayerFilename + ".zip"); if
		 * (downloaded) { Unzipper.unzip(new File(newPlayerFilename + ".zip"),
		 * new File(".")); } else { return; }
		 * Debug.msg("The new player has been downloaded.");
		 * Command.restartApplication();
		 */
		HttpRequest.getNewestPlayerVersion();
		Debug.log("Checking player upgrades", Debug.SYSTEM_LEVEL);
	}

	public static void main(String[] args) {
		downloadNewPlayer();
		System.exit(0);
	}

	@Override
	public void run() {
		boolean notUpdated = true;
		while (notUpdated) {
			//
			// try {
			// Thread.sleep(Settings.getUpgradeCheckerFrequency() *
			// 1000);//sleep for n minutes
			// } catch (InterruptedException ex) {
			// Logger.getLogger(UpdateChecker.class.getName()).log(Level.SEVERE,
			// null, ex);
			// }
			//
			// if (Helper.hasNetworkConnection() && hasNewVersion()) {
			// System.out.println("downloading new player");
			// downloadNewPlayer();
			//
			// } else {
			// }
		}
	}
}
